package org.flowers.unbeaten.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.flowers.unbeaten.base.entity.BaseEntity;
import org.flowers.unbeaten.base.entity.Role;
import org.flowers.unbeaten.logging.aop.annotation.Logging;
import org.flowers.unbeaten.logging.aop.enums.BusinessType;
import org.flowers.unbeaten.service.IRoleService;
import org.flowers.unbeaten.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author RyanWang
 * @since 2021-07-15
 */
@Api(tags = "后台系统-角色管理")
@RestController
@RequestMapping("/role/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @PostMapping("/list")
    @ApiOperation(value = "分页获取角色列表接口")
    @Logging(title = "角色管理", describe = "分页获取角色列表", type = BusinessType.QUERY)
    @RequiresPermissions("role:role:list")
    public DataResult list(@RequestBody Role role, BaseEntity baseEntity) {
        return DataResult.success(roleService.getRolePageList(role, baseEntity));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增角色接口")
    @Logging(title = "角色管理", describe = "新增角色", type = BusinessType.ADD)
    @RequiresPermissions("role:role:add")
    public DataResult add(@RequestBody Role role) {
        roleService.add(role);
        return DataResult.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "编辑角色接口")
    @Logging(title = "角色管理", describe = "编辑角色", type = BusinessType.EDIT)
    @RequiresPermissions("role:role:edit")
    public DataResult edit(@RequestBody Role role) {
        roleService.edit(role);
        return DataResult.success();
    }

    @DeleteMapping("/delete/{ids}")
    @ApiOperation(value = "删除角色接口")
    @Logging(title = "角色管理", describe = "删除角色", type = BusinessType.REMOVE)
    @RequiresPermissions("role:role:delete")
    public DataResult delete(@PathVariable List<String> ids) {
        roleService.delete(ids);
        return DataResult.success();
    }

    @GetMapping("/detail/{roleId}")
    @ApiOperation(value = "角色详情接口")
    @Logging(title = "角色管理", describe = "角色详情", type = BusinessType.QUERY)
    @RequiresPermissions("role:role:detail")
    public DataResult detail(@PathVariable String roleId) {
        return DataResult.success(roleService.detail(roleId));
    }

}

